﻿using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace LyyCMS.Core.Models
{
    [Table("ArticleCategory")]
    public class ArticleCategory: Entity<int>, IHasCreationTime, IHasDeletionTime, IFullAudited
    {
        /// <summary>
        /// 分类名称
        /// </summary>
        [Required]
        [DisplayName("分类名称")]
        public string Title { get; set; }

        /// <summary>
        /// 父级ID
        /// </summary>
        [DisplayName("父级分类")]
        public int ParentId { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        [DefaultValue(99)]
        [DisplayName("排序")]
        public int SortId { get; set; }

        /// <summary>
        /// 所属文章
        /// </summary>
        [DisplayName("所属文章")]
        public virtual ICollection<Article> Articles { get; set; }

        /// <summary>
        /// 父级
        /// </summary>
        [DisplayName("父级分类")]
        public virtual ArticleCategory Father { get; set; }

        /// <summary>
        /// 子集
        /// </summary>
        [DisplayName("子级分类")]
        public virtual ICollection<ArticleCategory> Childs { get; set; }

        /// <summary>
        /// 所属频道
        /// </summary>
        public int ChannelId { get; set; }

        /// <summary>
        /// SEO标题
        /// </summary>
        [DisplayName("SEO标题")]
        public string SEOTitle { get; set; }
        /// <summary>
        /// SEO关键字
        /// </summary>
        [DisplayName("SEO Key")]
        public string SEOKey { get; set; }

        /// <summary>
        /// SEO描述
        /// </summary>
        [DisplayName("SEO描述")]
        public string SEODescription { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [DisplayName("创建人")]
        public virtual User CreatorUser { get; set; }

        [DisplayName("最后修改人")]
        public virtual User LastModifierUser { get; set; }

        [DisplayName("删除人")]
        public virtual User DeleterUser { get; set; }


        /// <summary>
        /// 所属频道
        /// </summary>
        public virtual Channel Channel { get; set; }

        [DisplayName("创建时间")]
        public DateTime CreationTime { get; set; }
        [DisplayName("删除时间")]
        public DateTime? DeletionTime { get; set; }

        [DisplayName("已删除?")]
        public bool IsDeleted { get; set; }

        [DisplayName("创建人")]
        public long? CreatorUserId { get; set; }
        [DisplayName("修改人")]
        public long? LastModifierUserId { get; set; }
        [DisplayName("修改时间")]
        public DateTime? LastModificationTime { get; set; }
        [DisplayName("删除人")]
        public long? DeleterUserId { get; set; }


    }
}
/*
protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Test>().HasKey(t => t.Id);
            modelBuilder.Entity<Test>()
                        .HasMany(t => t.Childs)
                        .WithOptional(t => t.Father)
                        .HasForeignKey(t => t.Pid);
        }
 */
/*
 foreach (var t in context.Tests.Include("Childs"))
                {
                    foreach (var child1 in t.Childs)
                    {
                        Console.WriteLine("{0}, {1}, {2}", child1.Id, child1.Pid, child1.Name);
                    }
                    Console.WriteLine("{0}, {1}, {2}", t.Id, t.Pid, t.Name);
                }
 */
